# base_window.py
from PySide6.QtWidgets import QMainWindow
from PySide6.QtCore import Signal,Qt

class BaseMainWindow(QMainWindow):
    """所有主窗的公共基类，只做两件事：发信号 + 关闭时清理"""
    selected = Signal(str)          # 报告选中
    closed   = Signal(str)          # 报告关闭

    def __init__(self, uid: str, ctrl):
        super().__init__()
        self._uid = uid
        self._ctrl = ctrl
        self.setWindowTitle(f"EDA - {uid}")
        self.setAttribute(Qt.WA_DeleteOnClose)   # 必须，防止 C++ 对象残留

    # 子类在适当时候调用
    def emit_selected(self, uuid: str):
        self.selected.emit(uuid)
        self._ctrl.selection_changed.emit(uuid)

    def closeEvent(self, event):
        self.closed.emit(self._uid)
        print("close window:",self._uid)
        super().closeEvent(event)